package wymiana.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import wymiana.dao.PhotoDao;
import wymiana.domain.Photo;

@Service("photoService")
@Transactional
public class PhotoService {

	@Autowired
	private PhotoDao photoDao;
	
	public void create(Photo p_photo) {
		photoDao.save(p_photo);
	}
	
	public void deleteById(Integer p_id) {
		Photo photo = photoDao.getById(p_id);
		if (photo != null) {
			photoDao.delete(photo);
		}
	}
	public List<Photo> getallPhotos() {
		return photoDao.getAll();
	}
	
	public Photo getPhotoById(Integer p_id) {
		return photoDao.getById(p_id);
	}

	public void update(Photo p_photo) {
		photoDao.merge(p_photo);
	}
	
	public void addPhotos(List<Photo> photos){
		for(Photo p: photos){
			photoDao.save(p);
		}
	}

}
